﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;

namespace Catering_Rules
{
    public class StaffLessonsTests
    {
        private readonly Catering_Operation.StaffLessonsTests dal=new Catering_Operation.StaffLessonsTests();
		public StaffLessonsTests()
		{}
		#region  BasicMethod

		/// <summary>
		/// 得到最大ID
		/// </summary>
		public int GetMaxId()
		{
			return dal.GetMaxId();
		}

		/// <summary>
		/// 是否存在该记录
		/// </summary>
		public bool Exists(int LessonID,int TestID)
		{
			return dal.Exists(LessonID,TestID);
		}

		/// <summary>
		/// 增加一条数据
		/// </summary>
		public bool Add(Catering_Model.StaffLessonsTests model)
		{
			return dal.Add(model);
		}

		/// <summary>
		/// 更新一条数据
		/// </summary>
		public bool Update(Catering_Model.StaffLessonsTests model)
		{
			return dal.Update(model);
		}

		/// <summary>
		/// 删除一条数据
		/// </summary>
		public bool Delete(int LessonID,int TestID)
		{
			
			return dal.Delete(LessonID,TestID);
		}

		/// <summary>
		/// 得到一个对象实体
		/// </summary>
		public Catering_Model.StaffLessonsTests GetModel(int LessonID,int TestID)
		{
			
			return dal.GetModel(LessonID,TestID);
		}

		
		/// <summary>
		/// 获得数据列表
		/// </summary>
		public DataSet GetList(string strWhere)
		{
			return dal.GetList(strWhere);
		}
		/// <summary>
		/// 获得前几行数据
		/// </summary>
		public DataSet GetList(int Top,string strWhere,string filedOrder)
		{
			return dal.GetList(Top,strWhere,filedOrder);
		}
		/// <summary>
		/// 获得数据列表
		/// </summary>
		public List<Catering_Model.StaffLessonsTests> GetModelList(string strWhere)
		{
			DataSet ds = dal.GetList(strWhere);
			return DataTableToList(ds.Tables[0]);
		}
		/// <summary>
		/// 获得数据列表
		/// </summary>
		public List<Catering_Model.StaffLessonsTests> DataTableToList(DataTable dt)
		{
			List<Catering_Model.StaffLessonsTests> modelList = new List<Catering_Model.StaffLessonsTests>();
			int rowsCount = dt.Rows.Count;
			if (rowsCount > 0)
			{
				Catering_Model.StaffLessonsTests model;
				for (int n = 0; n < rowsCount; n++)
				{
					model = dal.DataRowToModel(dt.Rows[n]);
					if (model != null)
					{
						modelList.Add(model);
					}
				}
			}
			return modelList;
		}

		/// <summary>
		/// 获得数据列表
		/// </summary>
		public DataSet GetAllList()
		{
			return GetList("");
		}

		/// <summary>
		/// 分页获取数据列表
		/// </summary>
		public int GetRecordCount(string strWhere)
		{
			return dal.GetRecordCount(strWhere);
		}
		/// <summary>
		/// 分页获取数据列表
		/// </summary>
		public DataSet GetListByPage(string strWhere, string orderby, int startIndex, int endIndex)
		{
			return dal.GetListByPage( strWhere,  orderby,  startIndex,  endIndex);
		}
		/// <summary>
		/// 分页获取数据列表
		/// </summary>
		//public DataSet GetList(int PageSize,int PageIndex,string strWhere)
		//{
			//return dal.GetList(PageSize,PageIndex,strWhere);
		//}

		#endregion  BasicMethod
		#region  ExtensionMethod

        /// <summary>
        /// 获得数据列表
        /// </summary>
        public DataSet ViewGetList(string strWhere)
        {
            return dal.ViewGetList(strWhere);
        }

        /// <summary>
        /// 删除一条数据
        /// </summary>
        public bool Delete(int LessonID)
        {
            DataTable dt_BooksList = ViewGetList(" 1=1 AND LessonID=" + LessonID + " ").Tables[0];
            foreach (DataRow rt in dt_BooksList.Rows)
            {
                int intBookID = int.Parse(rt["TestID"].ToString());
                if (intBookID > 0) new Catering_Rules.Tests().Delete(intBookID);
            }
            return dal.Delete(LessonID);
        }

		#endregion  ExtensionMethod
    }
}
